export class ClaerWidgetCommand {
  constructor(widgetList, selectWidget, selectedWidget, widgetMap) {
    this.widgetList = widgetList
    this.originWidgetList = [...widgetList]
    this.selectWidget = selectWidget
    this.widgetMap = widgetMap
    // 保存一份源map，用于回退
    this.originMap = new Map(Array.from(widgetMap));
    this.selectedWidget = selectedWidget
  }
  execute() {
    // 删除所有物料，不能使用 this.widgetList = []，因为这只是更改了本实例中widgetList的指向
    this.widgetList.splice(0, this.widgetList.length)
    this.selectWidget(null)
    this.widgetMap.clear()
  }
  undo() {
    this.widgetList.push(...this.originWidgetList)
    this.selectWidget(this.selectedWidget)
    this.widgetMap = new Map(Array.from(this.originMap));
  }
}
